package com.visionvera.tools;

import java.io.File;
import java.io.FilenameFilter;

/**
 * Created by Qiao on 2016/12/16.
 */

public class RenamePngFiles {
    public static final String mDesDir = "./app/src/main/res/drawable";
    public static final String mOriginDir = "./tools/src/drawable";

    public static void main(String[] args) {
        System.out.print("START !" + "\n");

        File originDir = new File(mOriginDir);
        if (!originDir.exists()) {
            originDir.mkdirs();
        }
        File[] files = originDir.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".png") || name.endsWith(".jpg");
            }
        });
        for (File file : files) {
            String name = file.getName();
            name = name.replace("--", "_");
            name = name.replace("-", "_");
            for (int i = 0; i < name.length(); i++) {
                char charAt = name.charAt(i);
                if (charAt >= 'A' && charAt <= 'Z') {
                    String s = String.valueOf(charAt);
                    name = name.replace(s, "_" + s.toLowerCase());
                }
            }
            file.renameTo(new File(mDesDir, name));
            System.out.print(file.getName() + " renamed to " + name + "\n");
        }
        System.out.print("ALL DONE !");
    }
}
